<?php
session_start();
function success($a){
    $result = [
        'error'=> 0,
        'message' => $a
    ];
    return json_encode($result);
}
function error($msg){
    $data = [
        'error'=> 1,
        'message' => $msg
    ];
    return json_encode($data);
}

try{
    $db = new PDO('mysql:dbname=qq;host=127.0.0.1','root','123456');
    $statement = $db ->query('select * from (select * from history order by id desc LIMIT 0,9) as a order by id;');
    $state = $statement->fetchAll();


    if($state) {
        echo success($state);
    }else{
        echo error('发送失败！');
    }


}catch (PDOException $e){
    echo $e -> getMessage();
}
